/**
 * 前端登录业务类
 * @author singwa
 */
var login = {
    check : function() {
        // 获取登录页面中的用户名 和 密码
        var username = $('input[name="username"]').val();
        var password = $('input[name="password"]').val();
        var type=$('input[name="user"]:checked').val();
        console.log(type);
        if(!username) {
            dialog.error("用户名不能为空");
        }
        else if(!password) {
            dialog.error('密码不能为空');
        }
        else if(!type){
            dialog.error('登陆类型不能为空');
            $(window).attr('location','/index.php');
        }
        else{
            var url = "/index.php?c=login&a=check";
            var data = {'username':username,'password':password,'type':type};
            // 执行异步请求  $.post
            $.post(url,data,function(result){
                if(result.status == 0) {
                    return dialog.error(result.message);
                }
                if(result.status == 1) {
                    if(type=='admin'){
                        return dialog.success(result.message, '/index.php?c=admin&a=index');
                    }
                    if(type=='driver'){
                        return dialog.success(result.message,'/index.php?c=driver&a=index');
                    }
                }
            },'JSON');
        }

    }
}
